package basic.study.leetcode;

/**
 * @ClassName Easy21
 * @Description 合并两个有序链表
 * @Company inspur
 * @Author Kevin
 * @Date 2020/6/18 9:23
 * @Version 1.0
 */
public class Easy21 {

    public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
        ListNode solder = new ListNode(-1);
        ListNode node = solder;
        while (l1 != null && l2 != null) {
            if (l1.val > l2.val) {
                node.next = l2;
                l2 = l2.next;
                node = node.next;
            } else {
                node.next = l1;
                l1 = l1.next;
                node = node.next;
            }
        }
        if (l1 == null) {
            node.next = l2;
        } else if (l2 == null){
            node.next = l1;
        }

        return solder.next;
    }


    class ListNode {
        int val;
        ListNode next;
        ListNode(int x) { val = x; }
    }
}
